package com.yboot.starter.tenant.config;

import com.yboot.starter.common.core.security.UserContext;
import com.yboot.starter.tenant.core.api.DefaultTenantIdApi;
import com.yboot.starter.tenant.core.api.TenantIdApi;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
@AutoConfigureOrder(1)
@ConditionalOnProperty(
    prefix = "business.tenant",
    value = {"enable"},
    havingValue = "true",
    matchIfMissing = true
)
public class TenantMissingBeanAutoConfiguration {
    public TenantMissingBeanAutoConfiguration() {
    }

    @Bean
    @ConditionalOnMissingBean({TenantIdApi.class})
    public TenantIdApi tenantInfoApi(UserContext userContext) {
        return new DefaultTenantIdApi(userContext);
    }
}